
export default G6 => {
    G6.registerBehavior('active-edge', {
        getDefaultCfg() {
            return {

            }
        },
        getEvents() {
            return {
                'edge:click': 'onEdgeClick',
                'edge:dblclick': 'onEdgeDblClick',
                'edge:mouseenter': 'onEdgeMouseEnter',
                'edge:mousemove': 'onEdgeMouseMove',
                'edge:mouseleave': 'onEdgeMouseLeave',
                'edge:contextmenu': 'onEdgeContextmenu'
            }
        },
        onEdgeClick(e) {
            this._clearSelected();
            const graph = this.graph;
            const item = e.item;
            graph.setItemState(item, 'edgeState', 'selected');
            // 将点击事件发送给 graph 实例
            graph.emit('after-edge-selected', e);
        },
        onEdgeDblClick(e) {
            const graph = this.graph;
            const item = e.item;
            graph.setItemState(item, 'edgeState', 'selected');
            // 将双击事件发送给 graph 实例
            graph.emit('after-edge-dblClick', e);
        },
        onEdgeMouseEnter(e) {
            const graph = this.graph;
            const item = e.item;
            if (!item.hasState('edgeState:hover') && !item.hasState('edgeState:selected')) {
                graph.setItemState(item, 'edgeState', 'hover');
            }
            graph.emit('on-edge-mouseenter', e);
        },
        onEdgeMouseMove(e) {
            this.graph.emit('on-edge-mousemove', e);
        },
        onEdgeMouseLeave(e) {
            const graph = this.graph;
            const item = e.item;
            if (!item.hasState('edgeState:selected')) {
                graph.setItemState(item, 'edgeState', 'default');
            }
            graph.emit('on-edge-mouseleave', e);
        },
        onEdgeContextmenu(e) {
            this.graph.emit('on-editor-contextmenu', {
                type: 'edge',
                event: e
            })
        }, // 清除选中的节点和边样式
        _clearSelected() {
            let graph = this.graph;
            const selectNodes = this.graph.findAllByState('node', 'nodeState:selected');
            selectNodes.forEach(node => {
                graph.setItemState(node, 'nodeState', 'default');
            })
            const selectEdges = this.graph.findAllByState('edge', 'edgeState:selected');
            selectEdges.forEach(edge => {
                graph.setItemState(edge, 'edgeState', 'default');
            })
        }
    })
}